winston = require 'winston'
path = require 'path'
fs = require 'fs'
util = require 'util'

_exists = (folder)->
	if fs.existsSync
		fs.existsSync folder
	else
		path.existsSync folder

module.exports =
	getLogger:(name='master')->

		filename = path.resolve __dirname, "../logs/#{name}.log"
		folder = path.dirname filename

		unless _exists folder
			fs.mkdirSync folder
		logger = new winston.Logger
			levels: 
				info:0
				warn:1
				debug:2
				error:3
				fatal:4
			transports: [
				new winston.transports.Console()
				new winston.transports.File
					filename: filename
					level: 'warn'
					json: false
			]
		logger.logError = (err) ->
			logger.error err.stack ? util.inspect err if err
		logger